package week05.q2;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import week05.q2.BeanConfig;
import week05.q2.Import1;
import week05.q2.beans.SuperUser;
import week05.q2.beans.User;

/**
 * @author lv
 * @date 2021/4/15 21:34
 */
public class AssembleBean {
    public static void main(String[] args) throws InterruptedException {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        ApplicationContext context2 = new AnnotationConfigApplicationContext(BeanConfig.class);
        ApplicationContext context3 = new AnnotationConfigApplicationContext(Import1.class);

        User user1 = (User)context.getBean("user1");//第一种方式：通过xml配置
        User user21 = (User)context.getBean("user2");//第二种方式：通过@Component注解的方式
        User user31 = (User)context.getBean("user3");//第三种方式：Configuration获取@Bean的方式
        User user32 = (User)context2.getBean("user3");//第四种方式：通过@Bean的方式
        System.out.println(user32.getId());
        SuperUser superUser = (SuperUser)context3.getBean("superUser");//第5种方式：通过import的方式引入bean
        SuperUser superUser2 = (SuperUser)context3.getBean("superUser2");//第6种方式：通过import的方式引入bean
        User user22 = (User)context3.getBean("user2");//第7种方式：通过ImportBeanDefinitionRegistrar
    }
}